package org.qingke.mail.common;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Cookie帮助类
 * @author Administrator
 *
 */
public class CookieHelper {
    /**
     * 获取cookie
     * @param name
     * @param request
     * @return
     */
	public static String getCookie(String name,HttpServletRequest request){
		Cookie[] cookies=request.getCookies();
		if(null!=cookies){
			for(Cookie cookie:cookies){
				if(null!=cookie&&cookie.getName().equals(name)){
					return cookie.getValue();
				}
			}
		}
		return null;
	}
	/**
	 * 设置cookie
	 * @param name
	 * @param value
	 * @param response
	 */
	public static void setCookie(String name,String value,HttpServletResponse response){
		Cookie cookie=new Cookie(name, value);
		response.addCookie(cookie);
	}
	/**
	 * 清空cookie
	 * @param name
	 * @param response
	 */
	public static void delCookie(String name,HttpServletResponse response){
		Cookie cookie=new Cookie(name, null);
		cookie.setMaxAge(0);
		response.addCookie(cookie);
	}
}
